home *** CD-ROM | disk | FTP | other *** search
- #include "loadsave.h"
- #include "bitmap.h"
- #include "drawwin.h"
-
- #include "iff.h"
-
- #include<libraries/asl.h>
-
- #include<string.h>
- #include<stdio.h>
-
- #include<clib/asl_protos.h>
- #include<clib/dos_protos.h>
- #include<clib/graphics_protos.h>
-
- /* The size of our filename string */
- #define MAXFILENAME (300)
-
- /* Global handles for our requesters */
- static struct FileRequester* loadreq = NULL;
- static struct FileRequester* savereq = NULL;
-
- /* Open an ASL load file requester */
- void load(struct Window* win)
- {
- /* Allocate the requester if we haven't already */
- if(loadreq == NULL)
- loadreq = (struct FileRequester*)
- AllocAslRequestTags(ASL_FileRequest,
- ASLFR_TitleText, "Load File",
- ASLFR_Flags1, FRF_DOPATTERNS,
- ASLFR_InitialPattern, "#?.iff",
- TAG_DONE);
- if(loadreq)
- {
- if(AslRequestTags(loadreq, ASLFR_Window, win, TAG_DONE))
- {
- char filename[MAXFILENAME];
- /* Create complete filename from ASL's dir and file */
- strcpy(filename, loadreq->rf_Dir);
- if(AddPart(filename, loadreq->rf_File, MAXFILENAME))
- {
- IFFL_HANDLE handle;
- /* Try to open the IFF file */
- if(handle = IFFL_OpenIFF(filename, IFFL_MODE_READ))
- {
- LONG count;
- UWORD colortable[256];
- /* Get colour information and change screen colours */
- count = IFFL_GetColorTab(handle, colortable);
- LoadRGB4(&(win->WScreen->ViewPort), colortable, count);
- /* If we can load the picture, update window's display */
- if(IFFL_DecodePic(handle, getBitmap()))
- CopySBitMap(win->WLayer);
- else
- printf("Error: could not decode IFF picture\n");
- IFFL_CloseIFF(handle);
- }
- else
- printf("Error: could not open IFF file\n");
- }
- else
- printf("Error: could not make filename\n");
- }
- /* else: requester was cancelled */
- }
- else
- printf("Error: could not allocate ASL (load) file request\n");
- }
-
- /* Open an ASL save file requester */
- void save(struct Window* win)
- {
- /* Another way of saying "allocate if we haven't already" */
- if(savereq ||
- (savereq = (struct FileRequester*)
- AllocAslRequestTags(ASL_FileRequest,
- ASLFR_TitleText, "Save File",
- ASLFR_Flags1, FRF_DOPATTERNS | FRF_DOSAVEMODE,
- ASLFR_InitialPattern, "#?.iff",
- ASLFR_InitialFile, "picture.iff",
- TAG_DONE)))
- {
- if(AslRequestTags(savereq, ASLFR_Window, win, TAG_DONE))
- {
- char filename[MAXFILENAME];
- /* Create complete filename from ASL's dir and file */
- strcpy(filename, savereq->rf_Dir);
- if(AddPart(filename, savereq->rf_File, MAXFILENAME))
- {
- /* Make sure our bitmap is the same as the display */
- SyncSBitMap(win->WLayer);
- /* Try saving our bitmap, using the screen's colours */
- if(IFFL_SaveBitMap(filename, getBitmap(),
- win->WScreen->ViewPort.ColorMap->ColorTable,
- IFFL_COMPR_BYTERUN1) == 0)
- printf("Error: could not write IFF picture\n");
- }
- else
- printf("Error: could not make filename\n");
- }
- /* else: requester was cancelled */
- }
- else
- printf("Error: could not allocate ASL (save) file request\n");
- }
-
- /* Free any requesters that may have been allocated */
- void freeReqs()
- {
- if(loadreq)
- {
- FreeAslRequest(loadreq);
- loadreq = NULL;
- }
- if(savereq)
- {
- FreeAslRequest(savereq);
- savereq = NULL;
- }
- }
-
-